<?php

namespace App\Http\Requests\AddressController;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class EditAddressRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $address = request()->route( 'address' );
        return [
            'address' => [
                'required',
                'wallet_address:'.$address->coin_id,
                Rule::unique('trading_addresses')
                    ->where('user_id', $this->user()->id)
                    ->where('coin_id', $this->input('coin_id'))
                    ->where('id', '<>', $address->id),
            ],
            'note' => ['required'],
            'tag' => ['nullable'],
        ];
    }
}
